export const handelTreeArray = (array:any,handelData:any, isSelectChild=false)=>{ //处理下拉管理区域列表
    handelData.forEach(em => {
        em.key = em.id;
        em.value = em.id;
        em.title = em.name;
        // 控制管理区域是否禁止选择父级
        em.disabled = isSelectChild;
        array.push({
            ...em,
            children : []
        });
        if(em.children && em.children.length > 0){
            handelTreeArray(
                array[array.length - 1].children,
                em.children
            )
        }
 });
}

export const complementNum = (num:number|string, length:number) => {
    for(var len = (num + "").length; len < length; len = num.length) {
     num = "0" + num;
    }
    return num;
}

//四舍五入保留2位小数（不够位数，则用0替补）
export const keepTwoDecimalFull = (num:number) => {
    var result = parseFloat(num);
    if (isNaN(result)) {
    alert('传递参数错误，请检查！');
    return false;
    }
    result = Math.round(num * 100) / 100;
    var s_x = result.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
    pos_decimal = s_x.length;
    s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
    s_x += '0';
    }
    return s_x;
   }

export const getRandomString = (len:number)=>{ //生成随机字符串 --- 
    // let _charStr = 'abacdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789', //包含数字
    let _charStr = 'abacdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ',//不包含数字
        min = 0, 
        max = _charStr.length-1, 
        _str = '';                    //定义随机字符串 变量
    //判断是否指定长度，否则默认长度为15
    len = len || 15;
    //循环生成字符串
    for(var i = 0, index; i < len; i++){
        index = (function(randomIndexFunc, i){         
                    return randomIndexFunc(min, max, i, randomIndexFunc);
                })(function(min, max, i, _self){
                    let indexTemp = Math.floor(Math.random()*(max-min+1)+min),
                        numStart = _charStr.length - 10;
                    if(i==0&&indexTemp >=numStart){
                        indexTemp = _self(min, max, i, _self);
                    }
                    return indexTemp ;
                }, i);
        _str += _charStr[index];
    }
    return _str;
}